import { reactive, nextTick } from 'vue'
import { dialogVisible, dialogForm, setDialogForm, disabled } from './dialog.js'
import { submit } from './search.js'
import { add, update } from '@api/psninfo/psninfo.js'

export function tabSelectionChange(val) {
  console.log(val)
}
export function click(page, size) {
  console.log(page, size)
  submit({ pageNo: page, pageSize: size })
}
export function deleteRow(index, rows) {
  rows.splice(index, 1)
}
export let tableData = reactive([])
export function createRow() {
  dialogVisible.value = true
  disabled.value = false
  nextTick(function () {
    dialogForm.value.resetFields()
  })
}
export function addRow(data, isEdit) {
  if (isEdit) {
    update(data).then(() => {
      submit()
    })
  } else {
    add(data).then(() => {
      submit()
    })
  }
}
export function detaileRow(data) {
  dialogVisible.value = true
  disabled.value = true
  // 在表单没有显示前赋值，会被表单认作默认值。猜测
  nextTick(function () {
    setDialogForm(data)
  })
}
export function editRow(data) {
  dialogVisible.value = true
  disabled.value = false
  nextTick(function () {
    setDialogForm(data)
  })
}
